<?php

class Model_properti_baru extends CI_Model {

    function __construct() {
        parent::__construct();
        $this->load->database();
        $this->load->helper('text');
    }

    function get_properti_baru() {        
        $sql = "SELECT *
                from properti_baru, developer, media
                where properti_baru.developer_id = developer.developer_id ";
        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            foreach ($query->result() as $value) {
                $a[] = $value;
            }
            return $a;
        } else { echo 'error';
            return FALSE;
        }
    }

    function get_prop_baru($where = array()) {
        $this->db->select('properti_id,nama,tipe,luas_bangunan,jml_kmr_tidur,jml_kmr_mandi,harga,sewa_beli');
        return $this->db->get_where('properti', $where);
    }

    function get_prop_detail($str_id=''){
        if($str_id == ''){
            return FALSE;
        }
        $sql = "SELECT *
                from properti_baru, developer
                where properti_baru.id_properti_baru = ? and properti_baru.developer_id = developer.developer_id";
        $query = $this->db->query($sql,$str_id);
        if($query->num_rows() == 1){
            $value = $query->row();
            return $value;
        } else {
            return FALSE;
        }
    }

    function hapus_listing($where=array()){
        $this->db->trans_begin();
        $this->db->delete('properti',$where);
        if($this->db->trans_status()==FALSE){
            $this->db->trans_rollback();
            return FALSE;
        } else {
            $this->db->trans_commit();
            return TRUE;
        }
    }

}

?>